home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / rexx / center.pvrx < prev    next >
Text File  |  1995-03-03  |  3KB  |  132 lines

  1. /* $VER: Center.pvrx 3.0 (26.Jan.94) */
  2. /* This macro will get the coordinates of the center of the
  3.     bounding box of all selected objects, and move those objects so
  4.     that the new coordinates for the center of the bounding box are the
  5.     CENTER OF THE PAGE.
  6. Copyright © 1989-93 by Stylus, Inc.
  7. Author: Jeff Blume & Ross Cunniff
  8. Usage:  Assign to Ctrl-Key or RX tool
  9.     The macro expects to find at least one selected object. */
  10.  
  11. /*
  12. call open STDOUT,"RAM:RxOut.txt",W
  13. call open STDERR,"RAM:RxErr.txt",W
  14. trace R
  15. */
  16.  
  17. options results
  18.  
  19. /* Get the argument list to see whether if Ctrl-Key wants explicit "Both" */
  20. arg arglist
  21. Action = word(arglist,1)
  22.  
  23. /* Try to get exclusive lock on project window.
  24.     If can't get lock, not polite to interrupt. */
  25. 'Lock Wait'
  26. if rc ~= 0 then exit
  27.  
  28. /* Get coords of bounding box center */
  29. 'SelExtent' Ext
  30. if RC ~= 0 then call ERROR "No object selected!"
  31. CX = (Ext.X1 + Ext.X2) / 2
  32. CY = (Ext.Y1 + Ext.Y2) / 2
  33.  
  34. 'GetPageSize' Pdims
  35. CPX = (Pdims.X2 + Pdims.X1) / 2
  36. CPY = (Pdims.Y2 + Pdims.Y1) / 2
  37.  
  38. /*
  39. X-Y distance from center from the following:
  40. MX = (CPX - CX); MY = (CPY - CY)
  41. */
  42.  
  43. if Action ~= "BOTH" then call Request
  44. /*** If Action = "ACTION" then call Request ***/
  45. /***    then pass Horiz & Vert to...? ***/
  46.  
  47. select
  48.     when Action = "Horizontal" then do
  49.         MY = 0        /* Center Horizontal */
  50.         MX = (CPX - CX)
  51.         end
  52.     when Action = "Vertical" then do
  53.         MX = 0        /* Center Vertical */
  54.         MY = (CPY - CY)
  55.         end
  56.     when Action = "Origin" then do
  57.         MX = -Ext.X1
  58.         MY = -Ext.Y1
  59.         end
  60.     otherwise do
  61.         MX = (CPX - CX)    /* Center Both */
  62.         MY = (CPY - CY)
  63.         end
  64. end
  65.  
  66. 'SelectList' Sel; SelN = Result
  67.  
  68. 'PushUndo'
  69. do i = 0 for SelN
  70.     'Move'  Sel.i  MX MY
  71. end
  72.  
  73. CLEANUP:
  74.     'Repair'
  75.     'UnLock'
  76.  
  77.  
  78. EXIT
  79.  
  80.  
  81. ERROR:
  82.     arg ErrTxt
  83.     'GetBool ErrTxt "Cancel" "Cancel"'
  84.     'UnLock'
  85.     Exit
  86.  
  87.  
  88. REQUEST:
  89. if show("P","REXXREQUEST") then
  90.     do
  91.         call DefGads
  92.         address REXXREQUEST 'GetRequest Gads'; OK=Result
  93.         if OK > 0 then    /* The user didn't cancel the requester... */
  94.             do
  95.                 Action = Gads.1.Value
  96.                 Action = Gads.1.Descr.Action
  97.             end    /* end if do */
  98.         else call CleanUp    /* User canceled */
  99.     end
  100. else call error "No REXXRequest"
  101. return
  102.  
  103.  
  104. DEFGADS:
  105. /* Define PubScreen */
  106. Gads.PubScreen = "PROVECTOR"
  107.  
  108. /* Define Window */
  109. Gads.0.LeftEdge = 166; Gads.0.TopEdge = 70; Gads.0.Width = 324; Gads.0.Height = 50
  110. Gads.0.Label = "Center Selected Objects"
  111.  
  112. /* Define Cycle Gadget */
  113. Gads.1.LeftEdge = 160; Gads.1.TopEdge = 8; Gads.1.Width = 148; Gads.1.Height = 12
  114. Gads.1.Label = "Center Horiz/Vert"
  115. Gads.1.Type = Cycle
  116. Gads.1.Descr.0 = "Both"
  117. Gads.1.Descr.1 = "Horizontal"
  118. Gads.1.Descr.2 = "Vertical"
  119. Gads.1.Descr.3 = "Origin"
  120. Gads.1.Size = 4
  121. Gads.1.Value = "0"    /* initial/default */
  122.  
  123. /* Set up the OK and CANCEL buttons */
  124. Gads.2.LeftEdge = 16; Gads.2.TopEdge = 28; Gads.2.Width = 64; Gads.2.Height = 12
  125. Gads.2.Type = Button; Gads.2.Label = "OK"; Gads.2.EndGad = 1
  126. Gads.3.LeftEdge = 244; Gads.3.TopEdge = 28; Gads.3.Width = 64; Gads.3.Height = 12
  127. Gads.3.Type = Button; Gads.3.Label = "Cancel"; Gads.3.EndGad = -1
  128.  
  129. /* Total Gadgets + Window */
  130. Gads.NumGads = 4
  131. return    /* return DefGads */
  132.